//
//  CameraViewController.m
//  诚诚直播
//
//  Created by 张昊 on 16/7/9.
//  Copyright © 2016年 liaoyicheng. All rights reserved.
//

#import "CameraViewController.h"
#import "GPUImage.h"
#import "ALinGPUBeautifyFilter.h"

@interface CameraViewController ()<GPUImageVideoCameraDelegate>

@property(nonatomic,strong)GPUImageVideoCamera*videoCamera;
@property(nonatomic,strong)GPUImageView *filerView;

@end

@implementation CameraViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor hm_randomColor];
    
    //开启前置摄像头
    self.videoCamera = [[GPUImageVideoCamera alloc]initWithSessionPreset:AVCaptureSessionPreset1280x720 cameraPosition:AVCaptureDevicePositionFront];
    
    //程序界面的当前旋转方向 UIInterfaceOrientationPortrait 屏幕直立
    self.videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
    self.videoCamera.delegate = self;
    //前置摄像头是不是镜像
    self.videoCamera.horizontallyMirrorRearFacingCamera = YES;
    // 添加麦克风、声音的输入输出设备
    [self.videoCamera addAudioInputsAndOutputs];
    self.filerView = [[GPUImageView alloc]initWithFrame:self.view.bounds];
    self.filerView.center = self.view.center;
    [self.view insertSubview:self.filerView atIndex:0];
    [self.videoCamera addTarget:self.filerView];
    [self.videoCamera startCameraCapture];
    
        //默认开启美颜功能
    [self beautifulPhoto];
    
}

#pragma mark - 关闭直播
- (IBAction)closeCamera:(id)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - 开始照相
- (IBAction)startTakephoto:(id)sender {
}

#pragma mark - 开启美颜
- (IBAction)getBeautiful:(id)sender {
    
    
}

#pragma mark - 开始直播
- (IBAction)startTelevise:(id)sender {
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 美颜功能实现
-(void)beautifulPhoto{

    [self.videoCamera removeAllTargets];
    ALinGPUBeautifyFilter *filter = [[ALinGPUBeautifyFilter alloc]init];
    //input
    [self.videoCamera addTarget:filter];
    [filter addTarget:self.filerView];

}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
